/*
 * Powered By 
 * Since 2010 - 2016
 */

package com.rf.sys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rf.sys.dao.RoleResMapper;
import com.rf.sys.dao.SqlAdapterMapper;
import com.rf.sys.model.RoleRes;
import com.rf.sys.model.RoleResExample;
import com.rf.sys.model.RoleResExample.Criteria;
import com.rf.sys.service.RoleResService;
import com.rf.sys.utils.PageUtils;
import com.rf.sys.utils.UuidUtil;

@Service("roleResService")
public class RoleResServiceImpl implements RoleResService {
	
	@Autowired
   	private SqlAdapterMapper sqlAdapterMapper;//注入dao
   	@Autowired
   	private RoleResMapper roleResMapper;//注入dao

   	/**
	 * 根据id获取数据
	 * @param roleResId
	 * @return RoleRes
	 */
   	@Override
	public RoleRes getRoleResByID(String id) throws Exception{
		// TODO Auto-generated method stub
		return roleResMapper.selectByPrimaryKey(id);
	}
	
	/**
	 * 根据RoleRes获取数据
	 * @param RoleRes
	 * @return List<RoleRes>
	 */
	@Override
	public List<RoleRes> getRoleRes(RoleRes roleRes) throws Exception{
		// TODO Auto-generated method stub
		RoleResExample example = new RoleResExample();
		Criteria criteria = example.createCriteria();
		if(roleRes.getRoleId() != null && !roleRes.getRoleId().equals("")){
			criteria.andRoleIdEqualTo(roleRes.getRoleId());
		}
		if(roleRes.getResId() != null && !roleRes.getResId().equals("")){
			criteria.andResIdEqualTo(roleRes.getResId());
		}
		List<RoleRes> list = roleResMapper.selectByExample(example);
		return list;
	}
	
	/**
	 * 获取所有数据
	 * @param 
	 * @return List<RoleRes>
	 */
	@Override
	public List<RoleRes> getRoleRes() throws Exception{
		// TODO Auto-generated method stub
		RoleResExample example = new RoleResExample();
		return roleResMapper.selectByExample(example);
	}
   	
	/**
	 * 保存信息
	 * @param RoleRes
	 * @return
	 */
	@Override
	public void addRoleRes(RoleRes roleRes) throws Exception{
		// TODO Auto-generated method stub
		roleRes.setId(UuidUtil.get32UUID());
		roleResMapper.insert(roleRes);
	}

	/**
	 * 修改数据
	 * @param RoleRes
	 * @param
	 */
	@Override
	public void updateRoleRes(RoleRes roleRes) throws Exception{
		// TODO Auto-generated method stub
		roleResMapper.updateByPrimaryKeySelective(roleRes);
	}
	
	/**
	 * 删除数据
	 * @param roleResId
	 * @param
	 */
	@Override
	public void deleteRoleRes(String id) throws Exception{
		// TODO Auto-generated method stub
		roleResMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 获取数据分页
	 * @param RoleRes
	 * @param limit
	 * @param offset
	 * @return Map
	 */
	@Override
	public Map getRoleResPage(RoleRes roleRes,PageUtils pageUtils) throws Exception{
		RoleResExample example = new RoleResExample();
		com.rf.sys.model.RoleResExample.Criteria criteria= example.createCriteria();
		
		//获取第page页，每页共rows条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		//下一条执行语句，即为要被转换的语句
		List<RoleRes> list = roleResMapper.selectByExample(example);
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
}

